const app = getApp()
import {
    storeBindingsBehavior
} from '../miniprogram_npm/mobx-miniprogram-bindings/index'
import {
    store
} from '../store/store'
const tab1 = [{
        "pagePath": "/pages/index/index",
        "iconPath": "/image/18.png",
        "selectedIconPath": "/image/14.png",
        "text": "主页"
    },
    {
        "pagePath": "/pages/message/message",
        "iconPath": "/image/19.png",
        "selectedIconPath": "/image/15.png",
        "text": "消息"
    },
    {
        "pagePath": "/pages/knowledge/knowledge",
        "iconPath": "/image/20.png",
        "selectedIconPath": "/image/16.png",
        "text": "知识库"
    },
    {
        "pagePath": "/pages/my/my",
        "iconPath": "/image/21.png",
        "selectedIconPath": "/image/17.png",
        "text": "我的"
    }
]
const tab2 = [{
    "pagePath": "/pages/index/index",
    "iconPath": "/image/18.png",
    "selectedIconPath": "/image/14.png",
    "text": "主页"
},
{
    "pagePath": "/pages/message/message",
    "iconPath": "/image/19.png",
    "selectedIconPath": "/image/15.png",
    "text": "消息"
},
{
  "pagePath": "/pages/knowledge/knowledge",
  "iconPath": "/image/20.png",
  "selectedIconPath": "/image/16.png",
  "text": "知识库"
},
{
    "pagePath": "/pages/my/my",
    "iconPath": "/image/21.png",
    "selectedIconPath": "/image/17.png",
    "text": "我的"
}
]
Component({
    behaviors: [storeBindingsBehavior],
    storeBindings: {
        store,
        fields: {
            sum: "sum",
            active: 'activeTabBarIndex',
        },
        actions: {
            updateActive: 'updateActiveTabBarIndex'
        },
    },
    observers: {
        'sum': function (val) {
            // console.log(val);
            this.setData({
                'list[1].info': val > 0 ? val : 0 //三元运算符，如果数字徽标的数值小于零，就赋值为0
            })
        }
    },
    /**
     * 组件的属性列表
     */
    properties: {},
    data: {
        active: 0,
        "color": "#333333",
        "selectedColor": "#F28C41",
        "borderStyle": "black",
        "backgroundColor": "#ffffff",
        list: [],
        show: false
    },

    attached() {

      
    },

    methods: {
        show(){
            let info = JSON.parse(wx.getStorageSync('hospitalInfo')) 
            console.log('8889999',info)
            if (info) {
                if (info.tenantId !== 'fddxekyyzzta001' && info.tenantId != 'shsxhyyebkta001') {
                    this.setData({
                        list:tab1
                    })
                } else {
                    this.setData({
                        list: tab2
                    })
                }
            }
        },
        onChange(event) {
            this.updateActive(event.detail)
            wx.switchTab({
                url: this.data.list[event.detail].pagePath,
            })
        },
        getHospital() {
            wx.request({
                url: app.getUrl('/xcx/queryHospDept'),
                method: 'GET',
                data: {
                    deptId: app.globalData.deptId
                },
                header: wx.getStorageSync('cookie'),
                success(res) {
                    if (res.data.code == 0) {
                        app.globalData.hospitalInfo = res.data.data
                       
                    }
                }
            })
        },
        switchTab(e) {
            const data = e.currentTarget.dataset
            const url = data.path
            wx.switchTab({
                url
            })
        },

    }
})